/**
 * 
 */
package com.explgo.backend.domain;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonManagedReference;

/**
 * @author Jialiang(Cain) Wang
 * 
 */
@Entity
public class Plan extends DescribableEntity {
	private static final long serialVersionUID = 8931764095054969787L;

	/**
	 * The plan creator.
	 * */
	private User author;

	/**
	 * The days in this plan.
	 * */
	private List<PlanDay> days = new LinkedList<>();

	/**
	 * The count of liks on this plan
	 * */
	private long likeCount;

	/**
	 * The city this plan is in.
	 * */
	private City city;

	/**
	 * The plan comments.
	 * */
	private List<Comment> comments = new ArrayList<>();

	/**
	 * @return the author
	 */
	@ManyToOne
	public User getAuthor() {
		return author;
	}

	/**
	 * @param author
	 *            the author to set
	 */
	public void setAuthor(User author) {
		this.author = author;
	}

	/**
	 * @return the days
	 */
	@OneToMany(cascade = { CascadeType.ALL }, orphanRemoval = true)
	public List<PlanDay> getDays() {
		return days;
	}

	/**
	 * @param days
	 *            the days to set
	 */
	public void setDays(List<PlanDay> days) {
		this.days = days;
	}

	/**
	 * @return the like
	 */
	@Transient
	public long getLikeCount() {
		return likeCount;
	}

	/**
	 * @param like
	 *            the like to set
	 */
	public void setLikeCount(long like) {
		this.likeCount = like;
	}

	/**
	 * @return the city
	 */
	@ManyToOne
	public City getCity() {
		return city;
	}

	/**
	 * @param city
	 *            the city to set
	 */
	public void setCity(City city) {
		this.city = city;
	}

	/**
	 * @return the comments
	 */
	@OneToMany(mappedBy = "plan", cascade = {CascadeType.ALL})
	@JsonManagedReference
	public List<Comment> getComments() {
		return comments;
	}

	/**
	 * @param comments
	 *            the comments to set
	 */
	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}

}
